home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / PSCALE.ZIP / PUTSCALE.ASM next >
Encoding:
Assembly Source File  |  1993-06-07  |  3.5 KB  |  135 lines

  1. ; C far-callable as:
  2. ; void PutScale (int imageSeg, int imageOff, int imageWidth, int imageHeight,
  3. ;        int destSeg, int destOff, int destWidth, int destStart, int SizeX,
  4. ;     int SizeY)
  5. ; set tab size to 8
  6.  
  7.  
  8.     .286
  9.     .model  large
  10.     .code
  11.  
  12. public  _PutScale
  13. _PutScale    proc    far
  14.  
  15.     arg    imageSeg,imageOff,imageWidth,imageHeight,destSeg,destOff,destWidth,destStart,SizeX,SizeY
  16.  
  17.     push    bp    ;preserve caller stack frame
  18.     mov       bp,sp   ;point to local stack frame
  19.  
  20.     pusha
  21.     push    es
  22.     push    ds
  23.  
  24.  
  25.     push      imageSeg
  26.     pop    ds                      ;DS image seg
  27.     push    destSeg
  28.     pop    es            ;ES dest seg
  29.     mov    si,imageOff        ;SI image start
  30.     mov       di,destStart        ;DI dest offset
  31.     mov       bh,byte ptr SizeX          ;BH xsize
  32.     mov    bl,byte ptr SizeY    ;BL ysize
  33.  
  34.     ;calculate x increment
  35.  
  36.     mov       ah,bh                   ;AX xsize*256
  37.     shr    ah,2            ; AH and /4 to avoid divide errors
  38.     xor       al,al                   ; AL clear
  39.     mov    dx,imageWidth        ;DX
  40.     div       dl            ;AX divide size*256 by image width
  41.     jz        falldone                ;AX zero, nothing to do
  42.     mov       bh,al                   ;BH X increment/4
  43.  
  44.     ;calculate y increment
  45.  
  46.     mov    ah,bl            ;AX ysize*256
  47.     shr    ah,2            ; AH and /4 to avoid divide errors
  48.     xor    al,al            ; AL clear
  49.     mov    dx,imageHeight        ;DX
  50.     div    dl            ;AX divide size*256 by image height
  51.     jz    falldone            ;AX zero, nothing to do
  52.     mov    bl,al            ;BL Y increment/4
  53.  
  54.     xor    ax,ax            ;AX clear
  55.     xor    cx,cx            ;CX clear
  56.     mov       dl,byte ptr imageHeight    ;DL row count
  57.  
  58. frowstart:
  59.     mov    ah,ch            ;AH,CH store copy of CH
  60.     push    bx            ;BX save
  61.     xor    bh,bh            ;BX use BL for increment
  62.     shl    bx,2            ;BX increment was /4 above
  63.     add    cx,bx            ;CX increment by BL
  64.     pop    bx            ;BX restore
  65.     mov    al,ch            ;AL,CH used part of counter to AL
  66.     sub    al,ah            ;number of rows to draw
  67.  
  68.     push    cx            ;CX save, X also uses this reg
  69.     xor    cx,cx            ;CX clear, start X counting at 0
  70.  
  71.     inc    al            ;AL increment for below decrement
  72. frowloop:
  73.     dec    al            ;AL MUST have added one above
  74.     jz    frowdone        ;AL done with this row
  75.  
  76.     push    ax            ;AX X will also use this reg
  77.     push    di                      ;DI save screen offset
  78.  
  79.     mov    dh,byte ptr imageWidth    ;DH pixel width
  80. fcolstart:
  81.     mov    ah,ch            ;AH,CH store copy of CH
  82.     push    bx            ;BX save
  83.     shr    bx,8            ;BX use BH for increment
  84.     shl    bx,2            ;BX increment was /4 above
  85.     add    cx,bx            ;CX increment by BH
  86.     pop    bx            ;BX restore
  87.     mov    al,ch            ;AL,CH used part of counter to AL
  88.     sub    al,ah            ;number of pixels to draw
  89.  
  90.     inc    al            ;AL increment for below decrement
  91. fcolloop:
  92.     dec       al                      ;AL Must have added one above
  93.     jz        fcoldone        ;AL Done with this pixel
  94.  
  95.     ;DRAW PIXEL
  96.     ;ADD IGNORE COLOR HANDLER HERE
  97.     mov     ah,byte ptr ds:[si]     ;AH one pixel from image
  98.     mov     byte ptr es:[di],ah     ;AH to dest, maybe screen
  99.  
  100.     inc     di                      ;DI inc dest pointer
  101.     jmp     fcolloop                ;DI Finish this pixel
  102.  
  103. fcoldone:
  104.     inc     si                      ;SI inc image
  105.     dec     dh                      ;DH count cols
  106.     jnz     fcolstart               ;more cols in row?
  107.  
  108.     pop     di
  109.     pop    ax            ;AX Y needs this counter reg
  110.  
  111.     sub    si,imageWidth        ;SI backup for row repeat
  112.     add     di,destWidth        ;DI advance to next row
  113.     jmp    frowloop        ;check for row repeating
  114.  
  115. frowdone:
  116.     add    si,imageWidth        ;SI advance to next row
  117.     pop    cx            ;CX done with it, Y inc needs it now
  118.  
  119.     dec     dl                      ;DL count rows
  120.     jnz     frowstart                  ;more lines in image?
  121.  
  122. falldone:
  123.     pop    ds
  124.     pop    es
  125.     popa
  126.  
  127.     pop    bp    ;restore caller stack frame
  128.     retf
  129. _PutScale    endp
  130.  
  131.  
  132. end
  133.  
  134.  
  135.